package com.opal.salescost.service.impl;

import com.opal.salescost.mapper.VCxSalescostZpMapper;
import com.opal.salescost.entity.SalesorgForm;
import com.opal.salescost.entity.table.VCxSalescostZp;
import com.opal.salescost.service.SalescostZpService;
import com.opal.system.service.StoredProcedureService;
import com.opal.utils.PageVOUtils;
import com.opal.vo.PageVO;
import org.apache.poi.ss.formula.functions.T;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
public class SalescostZpServiceImpl implements SalescostZpService {

    @Autowired
    private VCxSalescostZpMapper vCxSalescostZpMapper;

    @Autowired
    private SalescostZpService salescostZpService;


    @Override
    public List<VCxSalescostZp> findAll(SalesorgForm salesorgForm) {
        List<VCxSalescostZp>vCxSalescostZpList = vCxSalescostZpMapper.findAll(salesorgForm);
        return vCxSalescostZpList;
    }

    @Override
    public PageVO<T> getPage(SalesorgForm salesorgForm) {

        String Time = salesorgForm.getStartTime().substring(0, 7);
        //执行存储过程 再执行查询
        this.CallGpCxSaleccost(Time,salesorgForm.getPkSalesorg());
        int Total = salescostZpService.getCount(salesorgForm);
        List<VCxSalescostZp> vCxSalescostZpList = vCxSalescostZpMapper.getPage(salesorgForm);
        return PageVOUtils.success(Total, vCxSalescostZpList);
    }

    @Override
    public int getCount(SalesorgForm salesorgForm) {
        return vCxSalescostZpMapper.getCount(salesorgForm);
    }

    @Override
    public void CallGpCxSaleccost(String Time ,String pkSalesorg) {
        vCxSalescostZpMapper.CallGpCxSaleccost(pkSalesorg,Time);
    }
}
